<!--#include file="classData.asp"-->
<%
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.AddHeader "Pragma", "No-Cache"



	CurrentGroup = CInt(Request.QueryString("CurrentGroup"))
	'SeasonNum = Request.QueryString("SeasonNum")
	maid = CInt(Request.QueryString("maid"))
	mbid = CInt(Request.QueryString("mbid"))
	btype = Request.QueryString("btype")
	R1F = CInt(Request.QueryString("R1F"))
	R1S = CInt(Request.QueryString("R1S"))
	R2F = CInt(Request.QueryString("R2F"))
	R2S = CInt(Request.QueryString("R2S"))
	R3F = CInt(Request.QueryString("R3F"))
	R3S = CInt(Request.QueryString("R3S"))
	R3FD = CInt(Request.QueryString("R3FD"))
	R3SD = CInt(Request.QueryString("R3SD"))
	
'	Response.Write("CurrentGroup:"&CurrentGroup&vbcrlf)
'	Response.Write("maid:"&maid&vbcrlf)
'	Response.Write("mbid:"&mbid&vbcrlf)
'	Response.Write("btype:"&btype&vbcrlf)
'	Response.Write("R1F:"&R1F&vbcrlf)
'	Response.Write("R1S:"&R1S&vbcrlf)
'	Response.Write("R2F:"&R2F&vbcrlf)
'	Response.Write("R2S:"&R2S&vbcrlf)
'	Response.Write("R3F:"&R3F&vbcrlf)
'	Response.Write("R3S:"&R3S&vbcrlf)
'	Response.Write("R3FD:"&R3FD&vbcrlf)
'	Response.Write("R3SD:"&R3SD&vbcrlf)
	
	Select Case btype
	
		Case "c11"
			BaseNum = 95200
			CupLevel = "11"
			TarLevel = "12"
		Case "c12"
			BaseNum = 95300
			CupLevel = "12"
			TarLevel = "13"
		Case "c13"
			BaseNum = 95500
			CupLevel = "13"
			TarLevel = "15"
		Case "c15"
			CupLevel = "15"
	
	End Select
	

	set HuaObj = new sysData
	HuaObj.sqlConnOpen()

	set SystemRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery SystemRds,"sysVar",QueryStr,0," VarId = 1"
	
	CurrentSeason = SystemRds("CurrentSeason")

	SystemRds.Close

	SignA = 0
	SignB = 0

	DifFirst = R1F - R1S + R2F - R2S
	DifSecond = R1S - R1F + R2S - R2F
	
	AwayTotalFirst = R2F
	AwayTotalSecond = R1S
	
'	Response.Write("DifFirst:"&DifFirst&vbcrlf)
'	Response.Write("DifSecond:"&DifSecond&vbcrlf)
'	Response.Write("AwayTotalFirst:"&AwayTotalFirst&vbcrlf)
'	Response.Write("AwayTotalSecond:"&AwayTotalSecond&vbcrlf)
'	
'	Response.Write((R3F + R3FD)&vbcrlf)
'	Response.Write((R3S + R3SD)&vbcrlf)
	






	HuaObj.p_DbConnection.BeginTrans
	on error resume next


	If (DifFirst = DifSecond) AND (AwayTotalFirst = AwayTotalSecond) Then
	'Response.Write("a")

	
		InsertSql = "UPDATE CupPlan SET IfDone = 1,HomeScore = "&R1F&",AwayScore = "&R1S&",MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND RoundNum = 1 AND HomeId = "&maid&" AND AwayId = "&mbid
		HuaObj.SCommand(InsertSql)
		'Response.Write(InsertSql&vbcrlf)

		InsertSql = "UPDATE CupPlan SET IfDone = 1,HomeScore = "&R2S&",AwayScore = "&R2F&",MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND RoundNum = 2 AND HomeId = "&mbid&" AND AwayId = "&maid
		HuaObj.SCommand(InsertSql)

		InsertSql = "INSERT INTO CupPlan VALUES("&CurrentSeason&","&CupLevel&",3,"&maid&","&R3F&","&R3FD&","&mbid&","&R3S&","&R3SD&",1,'"&Date&"')"
		HuaObj.SCommand(InsertSql)
		
		If (R3F + R3FD) > (R3S + R3SD) Then
		'Response.Write("b")
		
		  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1F+R2F+R3F)&",Ranking = "&R3FD&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
		  HuaObj.SCommand(InsertSql)
		  
		  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1S+R2S+R3S)&",Ranking = "&R3SD&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
		  HuaObj.SCommand(InsertSql)
		  
		  If btype <> "c15" Then
		  
			InsertSql = "UPDATE AreaCup SET ManagerId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
			
			InsertSql = "UPDATE CupPlan SET HomeId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
			
			InsertSql = "UPDATE CupPlan SET AwayId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
		  
		  End If
		
		
		Else
		
		  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1F+R2F+R3F)&",Ranking = "&R3FD&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
		  HuaObj.SCommand(InsertSql)
		  
		  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1S+R2S+R3S)&",Ranking = "&R3SD&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
		  HuaObj.SCommand(InsertSql)
		  
		  If btype <> "c15" Then
		  
			InsertSql = "UPDATE AreaCup SET ManagerId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
			
			InsertSql = "UPDATE CupPlan SET HomeId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
			
			InsertSql = "UPDATE CupPlan SET AwayId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
			HuaObj.SCommand(InsertSql)
		  
		  End If
		
		End If


	Else
	
	
		InsertSql = "UPDATE CupPlan SET IfDone = 1,HomeScore = "&R1F&",AwayScore = "&R1S&",MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND RoundNum = 1 AND HomeId = "&maid&" AND AwayId = "&mbid
		HuaObj.SCommand(InsertSql)

		InsertSql = "UPDATE CupPlan SET IfDone = 1,HomeScore = "&R2S&",AwayScore = "&R2F&",MarkDate = '"&Date&"' WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND RoundNum = 2 AND HomeId = "&mbid&" AND AwayId = "&maid
		HuaObj.SCommand(InsertSql)
		
		
		If DifFirst = DifSecond Then
			
			If AwayTotalFirst > AwayTotalSecond Then
			
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1F+R2F)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
			  HuaObj.SCommand(InsertSql)
			  
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1S+R2S)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
			  HuaObj.SCommand(InsertSql)			
			
		 	  If btype <> "c15" Then
			
				InsertSql = "UPDATE AreaCup SET ManagerId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET HomeId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET AwayId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
			  
			  End If
			
			Else
			
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1F+R2F)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
			  HuaObj.SCommand(InsertSql)
			  
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1S+R2S)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
			  HuaObj.SCommand(InsertSql)			
			
		 	  If btype <> "c15" Then
			
				InsertSql = "UPDATE AreaCup SET ManagerId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET HomeId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET AwayId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
			  
			  End If
			
			End If
		
		Else
		
			If DifFirst > DifSecond Then
			
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1F+R2F)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
			  HuaObj.SCommand(InsertSql)
			  
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1S+R2S)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
			  HuaObj.SCommand(InsertSql)			
			
		 	  If btype <> "c15" Then
			
				InsertSql = "UPDATE AreaCup SET ManagerId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET HomeId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET AwayId = "&maid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
			  
			  End If
			
			Else
			
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 0,Goal = "&(R1F+R2F)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&maid
			  HuaObj.SCommand(InsertSql)
			  
			  InsertSql = "UPDATE AreaCup SET IfDone = 2,Score = 3,Goal = "&(R1S+R2S)&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&CupLevel&" AND ManagerId = "&mbid
			  HuaObj.SCommand(InsertSql)			
			
		 	  If btype <> "c15" Then
			
				InsertSql = "UPDATE AreaCup SET ManagerId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND ManagerId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET HomeId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND HomeId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
				
				InsertSql = "UPDATE CupPlan SET AwayId = "&mbid&" WHERE SeasonNum = "&CurrentSeason&" AND CupLevel = "&TarLevel&" AND AwayId = "&(BaseNum + CurrentGroup)
				HuaObj.SCommand(InsertSql)
			  
			  End If
			
			End If
		
		End If
	
	
	End If


	


	response.ContentType="text/xml"	
	Response.Write("<?xml version=""1.0"" encoding=""gb2312""?>"&vbcrlf)
	Response.Write("<xml>"&vbcrlf)


	if err.number =0 then  
    	HuaObj.p_DbConnection.CommitTrans  '如果没有conn错误，则执行事务提交
		Response.Write("<Shi ShiId = ""1"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	else 
    	HuaObj.p_DbConnection.RollbackTrans '否则回滚
		Response.Write("<Shi ShiId = ""0"">"&vbcrlf)
		Response.Write("</Shi>"&vbcrlf)
	end if

	Response.Write("</xml>"&vbcrlf)

	
	HuaObj.sqlConnClose()


%>
